package ru.belokuriha_online.resort_hotels_belokuriha;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;


public class About  extends Activity {
	String spprisepath, aboutkont;
	WebView webViewkont;
	int FlagOnlain;
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);
		try {
		spprisepath = getIntent().getExtras().getString("spprisepath");
		FlagOnlain = getIntent().getExtras().getInt("FlagOnlain");
		
		webViewkont = (WebView)findViewById(R.id.webView1);
		webViewkont.getSettings().setJavaScriptEnabled(false);
		webViewkont.loadDataWithBaseURL(null, getResources().getString(R.string.about_kont), "text/html", "UTF-8", null);
		
		
		final TextView aboutexit =(TextView) findViewById(R.id.textViewCloseabout);
		aboutexit.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				About.super.onDestroy();
				finish();
				About.super.onDestroy();
			}	
		});
	} catch (Exception e) {
		// TODO: handle exception
	}
	}


	public boolean onCreateOptionsMenu(Menu menu) { 

		getMenuInflater().inflate(R.menu.pmenu, menu);

		return true;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) { 

		if (FlagOnlain == 0) {
			menu.findItem(R.id.loaditem1).setVisible(true);
			menu.findItem(R.id.loaditem1).setEnabled(true);
			} else
			{			
			menu.findItem(R.id.loaditem1).setEnabled(false);
			menu.findItem(R.id.loaditem1).setVisible(false);
			}
			menu.findItem(R.id.pitem2).setEnabled(true);
			menu.findItem(R.id.abitem3).setEnabled(true);

		return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) { 

		case R.id.loaditem1:
			GoMain();
			break; 
		case R.id.pitem2:

			try {
				Intent Preferintent = new Intent(getApplicationContext(),PreferActivity.class);
				Preferintent.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(Preferintent, 0);
			} catch (Exception e) {

			}
			break; 
		case R.id.abitem3: 

			try {
				Intent intentapp = new Intent(getApplicationContext(), Aboutapp.class);
				intentapp.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(intentapp, 0);
			} catch (Exception e) {

			}
			break;
		}   


		return super.onOptionsItemSelected(item); 

	} 
	private void GoMain() {
		AlertDialog.Builder buildergomain = new AlertDialog.Builder(this);
		buildergomain.setTitle(R.string.lt_app);		
		buildergomain.setMessage(R.string.lmmm_app);		
		buildergomain.setNegativeButton(R.string.qn_app, null);
		buildergomain.setPositiveButton(R.string.qy_app, new OnClickListener() {
			public void onClick(DialogInterface arg0, int arg1) {
				setResult(7);
				About.super.onDestroy();
				finish(); 
				About.super.onDestroy();

			}
		}).create().show();	
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == 7) {
			setResult(7);
			About.super.onDestroy();
			finish();
			About.super.onDestroy();
			
		}

		if (resultCode ==  5) {
			try {
				openOptionsMenu();
			} catch (Exception e) {

			}
		}
		if (resultCode ==  9) {
			try {
				Intent Preferintent = new Intent(getApplicationContext(),PreferActivity.class);
				Preferintent.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(Preferintent,0);
			} catch (Exception e) {

			}
		}
		if (resultCode ==  10) {
			try {
				Intent intentapp = new Intent(getApplicationContext(), Aboutapp.class);
				intentapp.putExtra("FlagOnlain", FlagOnlain);
				startActivityForResult(intentapp,0);
			} catch (Exception e) {

			}
		}

	}
	@Override 
	protected void onDestroy() {
		super.onDestroy();
		webViewkont.clearCache(true);
		webViewkont.clearHistory();
		webViewkont.removeAllViews();
		webViewkont.destroy();
		System.gc();
	}
	@Override
	public void onBackPressed() {
		System.gc();
		About.super.onDestroy();
		finish();
		About.super.onDestroy();
	}

}